package com.coocaa.ops.admin.v1.device.service;

import com.coocaa.ops.admin.v1.device.biz.GlobalDeviceInfoBizImpl;
import com.coocaa.ops.admin.v1.device.converter.DeviceParamConverter;
import com.coocaa.ops.admin.v1.device.model.GlobalDeviceInfoModel;
import com.coocaa.ops.common.core.base.model.PageResultModel;
import com.coocaa.ops.common.core.biz.device.entity.GlobalDeviceInfoEntity;
import com.coocaa.ops.common.tool.date.DateUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author tangminghong
 * @date 2019.5.18
 */
@Service
public class GlobalDeviceServiceImpl implements IGlobalDeviceService {

    @Autowired
    private GlobalDeviceInfoBizImpl globalDeviceInfoBiz;

//    @Autowired
//    private IDeviceConfigService deviceConfigService;

    @Override
    public PageResultModel<GlobalDeviceInfoEntity> pageList(GlobalDeviceInfoModel model) {
        Map<String, Object> param = DeviceParamConverter.getParamMap(model);
        return globalDeviceInfoBiz.getCommonPageList(param, false);
    }

    @Override
    public void save(GlobalDeviceInfoEntity entity) {
        //为了不重复插入，先查询是否有已存在的信息
        List<GlobalDeviceInfoEntity> list = globalDeviceInfoBiz.getByChipModelAndPlatform(entity.getChip(), entity.getModel(), entity.getPlatform());
        if (CollectionUtils.isEmpty(list)) {
            entity.setCreatedDate(DateUtil.getCurDate());
            globalDeviceInfoBiz.add(entity);
//            addDeviceConfig(entity);
        }
    }

//    private void addDeviceConfig(GlobalDeviceInfoEntity entity) {
//        DeviceConfigInfoEntity configEntity = new DeviceConfigInfoEntity();
//        configEntity.setModel(entity.getModel());
//        configEntity.setChip(entity.getChip());
//        configEntity.setAutoPlay(DeviceConfigAutoPlayConstant.UNKNOWN);
//        configEntity.setRamSize("");
//        deviceConfigService.addAutoPlayConfig(configEntity, new SysUserInfo());
//    }
}
